<?php

declare(strict_types=1);

namespace sheep\channel;

use think\Model;
use think\facade\Log;
use yunwuxin\Notification;
use yunwuxin\notification\Channel;
use yunwuxin\notification\Notifiable;

class Database extends Channel
{

    /**
     * 发送站内信通知
     * 
     * @param Notifiable   $notifiable
     * @param Notification $notification
     * @return void
     */
    public function send($notifiable, Notification $notification)
    {
        $params = $this->getMessage($notifiable, $notification);

        /** @var Model $model */
        $model = $notifiable->getPreparedData('database');

        $model->save([
            'id'        => $notification->id,
            'notification_type'      => $notification->notification_type,
            'type'      => $notification->event,
            'data'      => $params,
            'read_time' => null
        ]);
    }
}